package com.yayohos.locationmanager.providers.dialogprovider;


import ohos.agp.window.dialog.BaseDialog;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.IDialog;
import ohos.app.Context;

/**
 * 通用的dialogProvider，调用者可以自定义
 *
 * @date 2021/5/26
 */
public class SimpleMessageDialogProvider extends DialogProvider implements IDialog.ClickedListener {
    private String message;

    public SimpleMessageDialogProvider(String message) {
        this.message = message;
    }

    /**
     * 获取 message
     * @return message
     */
    public String message() {
        return message;
    }

    @Override
    public BaseDialog getDialog(Context context) {
        CommonDialog commonDialog = new CommonDialog(context);
        commonDialog.setContentText(" " + message);
        commonDialog.setAutoClosable(false);
        commonDialog.setSize(900, 300);
        commonDialog.setButton(IDialog.BUTTON3, "确定", this);
        commonDialog.setButton(IDialog.BUTTON1, "取消", this);
        return commonDialog;
    }

    @Override
    public void onClick(IDialog iDialog, int button) {
        switch (button) {
            case IDialog.BUTTON1: // 取消
                if (getDialogListener() != null) {
                    getDialogListener().onNegativeButtonClick();
                    iDialog.destroy();
                }
                break;
            case IDialog.BUTTON3: // 确定
                if (getDialogListener() != null) {
                    getDialogListener().onPositiveButtonClick();
                    iDialog.destroy();
                }
                break;
            default:
                break;
        }
    }
}
